package com.aw.baselib.net.api

import android.util.Log
import com.aw.baselib.util.AwLog.d
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
 * Created by hzw
 */
class UrlInterceptorNoToken : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        Log.d(TAG, "UrlInterceptor_ " + System.currentTimeMillis())
        val oldRequest = chain.request()
        // 添加新的参数
        val authorizedUrlBuilder = oldRequest.url()
            .newBuilder()
            .scheme(oldRequest.url().scheme())
            .host(oldRequest.url().host())
        // 新的请求
        val newRequest =
            oldRequest.newBuilder() //                .addHeader("Accept-Encoding", "gzip")
                .addHeader("Accept", "application/json")
                .addHeader("Content-Type", "application/json; charset=utf-8")
                .method(oldRequest.method(), oldRequest.body())
                .url(authorizedUrlBuilder.build())
                .build()
        d(TAG, newRequest.toString())
        //响应信息拦截
        return chain.proceed(newRequest)
    }

    companion object {
        private const val TAG = "UrlInterceptor"
    }
}